home *** CD-ROM | disk | FTP | other *** search
- Path: Inter.NL.net!usenet
- From: Auke.Reitsma@net.HCC.nl (Auke Reitsma)
- Newsgroups: comp.lang.c
- Subject: Re: Who's dumb: me or my compiler ?
- Date: Mon, 12 Feb 1996 22:13:03 GMT
- Organization: Inter.NL.net, The Internet Provider in The Netherlands.
- Message-ID: <4foe8j$qvn@altrade.nijmegen.inter.nl.net>
- References: <4fnmhd$c1o@micky.ibh-dd.de>
- Reply-To: Auke.Reitsma@net.HCC.nl
- NNTP-Posting-Host: rt99-13.rotterdam.nl.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- beck@duck.ibh-dd.de (Andre Beck) wrote:
-
- > Hi,
-
- > I could have had a really bad day searching for this bug, but for
- > some lucky circumstances, I trapped it instantly. However I don't
- > know whether I wrote bad code or whether a number of compilers do
- > it wrong in the same way - the latter doesn't sound that probable ;)
-
- > My problem turns around the expression
-
- > x = (*ptr++ << 8) | *ptr++;
-
- Ouch. Order of evaluation, side effects. Undefined behaviour.
-
- > which is pretty simple (IMHO). Read two subsequent bytes from memory
- > and make a word off them. Not nice, I know, even endian-dependant. But
- > nothing to fail on. Now, GCC fails on 3 different platforms, and DEC
- > cc for Ultrix fails as well. Here's my trigger program:
-
- Possible solution:
-
- x = (*ptr++ << 8);
- x |= *ptr++;
-
-
- Greetings from Delft, The Netherlands.
-
- Auke Reitsma
-
-